﻿using MengLin.Studying.PrismApp.Models;
using Prism.Commands;
using Prism.Mvvm;
using System.Collections.ObjectModel;

namespace MengLin.Studying.PrismApp.ViewModel.First
{
    public class Protocol_SIS_ViewModel : BindableBase
    {
        private Protocol_SIS_Model _protocolSISModel;

        public Protocol_SIS_Model ProtocolSISModel
        {
            get => _protocolSISModel;
            set => SetProperty(ref _protocolSISModel, value);
        }

        public ObservableCollection<string> SensorModes { get; set; }
        public ObservableCollection<string> BackgroundModes { get; set; }
        public ObservableCollection<string> MixingModes { get; set; }

        public DelegateCommand IncreaseReplicatesCommand { get; }
        public DelegateCommand DecreaseReplicatesCommand { get; }

        public Protocol_SIS_ViewModel()
        {
            ProtocolSISModel = new Protocol_SIS_Model
            {
                SensorMode = "Extinction",
                MeasurementVolume = 0,
                SyringeFlowRate = 0,
                SizeThreshold = 0,
                SampleRunTime = 0,
                IsPreserveSample = false,
                IsLowVolume = false,
                IsTare = false,
                TareVolume = 0,
                IsFlush = false,
                BackgroundMode = "123",
                BackgroundMeasurement = 0,
                BackgroundMeasurementUnit = "abc",
                IsMixing = false,
                MixingMode = "Mode1",
                MixingCycles = 0,
                MixingVolume = 0,
                MixingFlowRate = 0,
                IsAutoStirrer = false,
                StirrerSpeed = 0,
                StirrerRunTime = 0,
                Replicates = 1,
                AirGapVolume = 0,
                DelayTime = 0
            };

            SensorModes = new ObservableCollection<string> { "Extinction", "Summation" };
            BackgroundModes = new ObservableCollection<string> { "123" };
            MixingModes = new ObservableCollection<string> { "Mode1", "Mode2", "Mode3" };

            IncreaseReplicatesCommand = new DelegateCommand(IncreaseReplicates);
            DecreaseReplicatesCommand = new DelegateCommand(DecreaseReplicates);
        }

        private void IncreaseReplicates()
        {
            ProtocolSISModel.Replicates++;
        }

        private void DecreaseReplicates()
        {
            if (ProtocolSISModel.Replicates > 1)
            {
                ProtocolSISModel.Replicates--;
            }
        }

        public bool IsReplicatesEnabled => ProtocolSISModel.Replicates > 1;
    }
}